package com.xbongbong.saas.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.paas.enums.FieldTypeEnum;
import com.xbongbong.paas.enums.ScreenTypeEnum;
import com.xbongbong.saas.enums.base.CustomerStatementStatisticBaseEnum;
import lombok.Getter;

/**
 * @Description
 * @author: shian
 * @date : 2021/1/11
 */
@Getter
public enum CustomerStatementStatisticDistributorEnum {
    // 基础信息
    BASE_INFO(CustomerStatementStatisticBaseEnum.BASE_INFO.getAttr(), "enum.customerManagement.attrName.base_info", "baseInfo", FieldTypeEnum.SEPARATOR.getType(), SetTypeEnum.DISABLE_REPEAT.getCode(), 1, 0, ShowTypeEnum.EDIT_DETAIL.getCode(), 11000, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),

    //对账单编号
    STATEMENT_NO(CustomerStatementStatisticBaseEnum.STATEMENT_NO.getAttr(),"enum.customerStatementStatisticEnum.attrName.statement_no","statementNo",FieldTypeEnum.SERIALNO.getType(),SetTypeEnum.DISABLE_ALL.getCode(),1,0,ShowTypeEnum.ALL.getCode(),10000,1,0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    //关联客户id
    CUSTOMER_ID(CustomerStatementStatisticBaseEnum.CUSTOMER_ID.getAttr(),"enum.customerStatementStatisticDistributorEnum.attrName.customer_id","customerId",FieldTypeEnum.LINK_BUSINESS_SINGLE.getType(),SetTypeEnum.DISABLE_ALL.getCode(),1,0,ShowTypeEnum.ALL.getCode(),9990,1,0,ScreenTypeEnum.SCREEN_GROUP.getType()),
    //对账单状态
    STATUS(CustomerStatementStatisticBaseEnum.STATUS.getAttr(),"enum.customerStatementStatisticEnum.attrName.status","status",FieldTypeEnum.COMBO.getType(),SetTypeEnum.DISABLE_ALL.getCode(),1,0,ShowTypeEnum.ALL.getCode(),9985,1,0,ScreenTypeEnum.SCREEN_GROUP.getType()),
    // 对账日期
    CHECK_DATE(CustomerStatementStatisticBaseEnum.CHECK_DATE.getAttr(),"enum.customerStatementStatisticEnum.attrName.checkDate","checkDate", FieldTypeEnum.CHECK_DATE.getType(), SetTypeEnum.DISABLE_ALL.getCode(),1, 0, ShowTypeEnum.ALL.getCode(),9980,1,0,ScreenTypeEnum.SCREEN_GROUP.getType()),
    //对账单生成日期
    CREATE_DATE(CustomerStatementStatisticBaseEnum.CREATE_DATE.getAttr(),"enum.customerStatementStatisticEnum.attrName.create_date","createDate",FieldTypeEnum.DATETIME.getType(),SetTypeEnum.DISABLE_ALL.getCode(),1,0,ShowTypeEnum.ALL.getCode(),9960,1,0,ScreenTypeEnum.SCREEN_GROUP.getType()),
    // 确认时间
    CONFIRM_DATE(CustomerStatementStatisticBaseEnum.CONFIRM_DATE.getAttr(),"enum.customerStatementStatisticEnum.attrName.confirm_date","confirmDate",FieldTypeEnum.DATETIME.getType(),SetTypeEnum.DISABLE_ALL.getCode(),1,0,ShowTypeEnum.ALL.getCode(),9960,1,0,ScreenTypeEnum.SCREEN_GROUP.getType()),
    //经销商的确认人（经销商确认）
    DEALER_CONFIRMOR(CustomerStatementStatisticBaseEnum.DEALER_CONFIRMOR.getAttr(),"enum.customerStatementStatisticEnum.attrName.dealer_confirmor","dealerConfirmor",FieldTypeEnum.LINK_BUSINESS_SINGLE.getType(),SetTypeEnum.DISABLE_ALL.getCode(),1,1,ShowTypeEnum.ALL.getCode(),99200,1,0,ScreenTypeEnum.SCREEN_OFF.getType()),

    ACCOUNTS_INFO(CustomerStatementStatisticBaseEnum.ACCOUNTS_INFO.getAttr(), "enum.customerStatementStatisticEnum.attrName.accounts_info", "accountsInfo", FieldTypeEnum.SEPARATOR.getType(), SetTypeEnum.DISABLE_REPEAT.getCode(), 1, 0, ShowTypeEnum.EDIT_DETAIL.getCode(), 9945, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    //应收款总额
    AMOUNT_RECEIVABLE_TOTAL(CustomerStatementStatisticBaseEnum.AMOUNT_RECEIVABLE_TOTAL.getAttr(),"enum.customerStatementStatisticEnum.attrName.amount_receivable_total","amountReceivableTotal",FieldTypeEnum.NUM.getType(),SetTypeEnum.DISABLE_ALL.getCode(),1,0,ShowTypeEnum.ALL.getCode(),9940,1,0,ScreenTypeEnum.SCREEN_GROUP.getType()),
    //回款金额
    AMOUNT_RECEIVED_TOTAL(CustomerStatementStatisticBaseEnum.AMOUNT_RECEIVED_TOTAL.getAttr(),"enum.customerStatementStatisticEnum.attrName.amount_received_total","amountReceivedTotal",FieldTypeEnum.NUM.getType(),SetTypeEnum.DISABLE_ALL.getCode(),1,0,ShowTypeEnum.ALL.getCode(),9890,1,0,ScreenTypeEnum.SCREEN_GROUP.getType()),
    //核销金额
    WRITE_OFF_AMOUNT_TOTAL(CustomerStatementStatisticBaseEnum.WRITE_OFF_AMOUNT_TOTAL.getAttr(),"enum.customerStatementStatisticEnum.attrName.write_off_amount_total","writeOffAmountTotal",FieldTypeEnum.NUM.getType(),SetTypeEnum.DISABLE_ALL.getCode(),1,0,ShowTypeEnum.ALL.getCode(),9880,1,0,ScreenTypeEnum.SCREEN_GROUP.getType()),
    //应收余额
    BALANCE_RECEIVABLE_TOTAL(CustomerStatementStatisticBaseEnum.BALANCE_RECEIVABLE_TOTAL.getAttr(),"enum.customerStatementStatisticEnum.attrName.balance_receivable_total","balanceReceivableTotal",FieldTypeEnum.NUM.getType(),SetTypeEnum.DISABLE_ALL.getCode(),0,1,ShowTypeEnum.ALL.getCode(),9930,1,1,ScreenTypeEnum.SCREEN_OFF.getType()),

    IS_ARCHIVED(CustomerStatementStatisticBaseEnum.IS_ARCHIVED.getAttr(), "enum.customerManagement.attrName.is_archived", "isArchived", FieldTypeEnum.COMBO_NUM.getType(), 1, 0, 1, ShowTypeEnum.NONE.getCode(), 9900, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    LINK_CUSTOMER(CustomerStatementStatisticBaseEnum.LINK_CUSTOMER.getAttr(),"enum.customerStatementStatisticDistributorEnum.attrName.customer_id","linkCustomer", FieldTypeEnum.TEXT.getType(), 1, 0, 1, ShowTypeEnum.NONE.getCode(), 9470, 1, 1, ScreenTypeEnum.SCREEN_OFF.getType()),
    OWNER_ID(CustomerStatementStatisticBaseEnum.OWNER_ID.getAttr(), "enum.salesOpportunity.attrName.owner_id", "ownerId", FieldTypeEnum.OWNERID.getType(), 1, 1, 0, ShowTypeEnum.ALL.getCode(), 9920, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),

    SYSTEM_INFO(CustomerStatementStatisticBaseEnum.SYSTEM_INFO.getAttr(), "enum.customerManagement.attrName.system_info", "systemInfo", FieldTypeEnum.SEPARATOR.getType(), SetTypeEnum.DISABLE_REPEAT.getCode(), 1, 0, ShowTypeEnum.EDIT_DETAIL.getCode(), 9670, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    CREATOR(CustomerStatementStatisticBaseEnum.CREATOR.getAttr(), "enum.customerManagement.attrName.creator", "creator", FieldTypeEnum.USER.getType(), 1, 0, 0, ShowTypeEnum.ALL.getCode(), 9660, 1, 1, ScreenTypeEnum.SCREEN_GROUP.getType()),
    ADD_TIME(CustomerStatementStatisticBaseEnum.ADD_TIME.getAttr(), "enum.customerStatementStatisticEnum.attrName.add_time", "addTime", FieldTypeEnum.ADDTIME.getType(), 1, 1, 0, ShowTypeEnum.ALL.getCode(), 9790, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    UPDATE_TIME(CustomerStatementStatisticBaseEnum.UPDATE_TIME.getAttr(), "enum.customerStatementStatisticEnum.attrName.update_time", "updateTime", FieldTypeEnum.UPDATETIME.getType(), 1, 1, 0, ShowTypeEnum.ALL.getCode(), 9780, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    CONFIRMOR_LINK_TEXT(CustomerStatementStatisticBaseEnum.CONFIRMOR_LINK_TEXT.getAttr(), "enum.customerStatementStatisticEnum.attrName.confirmor_link_text", "confirmorName", FieldTypeEnum.TEXT.getType(), 1, 0, 1, ShowTypeEnum.NONE.getCode(), 8970, 1, 1, ScreenTypeEnum.SCREEN_OFF.getType()),
    ;

    CustomerStatementStatisticDistributorEnum(String attr, String attrName, String saasAttr, Integer fieldType, Integer setType, Integer designEditable, Integer editHide, Integer showType, Integer sort, Integer visible, Integer required, Integer screenType) {
        this.attr = attr;
        this.attrName = attrName;
        this.saasAttr = saasAttr;
        this.fieldType = fieldType;
        this.setType = setType;
        this.designEditable = designEditable;
        this.editHide = editHide;
        this.showType = showType;
        this.sort = sort;
        this.visible = visible;
        this.required = required;
        this.screenType = screenType;
    }

    /**
     * 英文名称
     */
    private String attr;
    /**
     * 中文名称
     */
    private String attrName;
    /**
     * 对应saas中的attr
     */
    private String saasAttr;
    /**
     * 字段类型，详见
     *
     * @see FieldTypeEnum
     */
    private Integer fieldType;
    /**
     * 重命名、判重、启用必填等权限
     * 1.重命名+字段权限
     * 2.重命名+字段权限+查重
     * 3.重命名+字段权限+启用、必填
     * 4.重命名+字段权限+查重+启用、必填
     * 注：pro中启用和必填是同一个权限，同时启用或同时关闭
     */
    private Integer setType;
    /**
     * 模板设计阶段字段是否允许编辑
     * 1：允许编辑
     * 0：不允许编辑
     */
    private Integer designEditable;
    /**
     * 字段是否显示在模板设计界面
     * 1：不显示
     * 0：显示
     */
    private Integer editHide;
    /**
     * 字段在各个界面（新建、编辑、列表、详情）的展现形式
     * 详见
     *
     * @see ShowTypeEnum
     */
    private Integer showType;
    /**
     * 字段在模板设计界面的排序
     * 建议不要用连续的数字，可以用等差数列，以防以后在两个字段之间加入新字段
     */
    private Integer sort;
    /**
     * 字段在各个界面是否可见(启用)
     * 1：可见
     * 0：不可见
     * 注：字段在具体页面的可见性需要用属性和showType联合判断，在visible=1的情况下判断showType
     */
    private Integer visible;
    /**
     * 字段是否必填
     * 1：必填
     * 0：不必填
     */
    private Integer required;
    /**
     * 筛选类型
     * 1：可筛选
     * 2：不可筛选
     */
    private Integer screenType;

    public String getAttrName() {
        return I18nMessageUtil.getMessage(attrName);
    }

    public String getI18nAttrName() {
        return attrName;
    }

    public static String getEsAttr(CustomerStatementStatisticDistributorEnum cache) {
        FieldTypeEnum fieldTypeEnum = FieldTypeEnum.getFieldTypeEnum(cache.getFieldType());
        //字段类型为text，或者字段在es内的类型时text，则需要在后面拼上“.keyword”
        boolean flag = fieldTypeEnum == FieldTypeEnum.TEXT || "text".equals(fieldTypeEnum.getEsalias());
        if (flag) {
            return "data." + cache.getAttr() + ".keyword";
        }
        return "data." + cache.getAttr();
    }
}
